Thread: [Urgent] Can't recognize the last counter?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2017
    Posts
    13

    Question [Urgent] Can't recognize the last counter?

    Hey all, I just joined the forum! My name is Sam.
    I have an assignment due in a few hours, and I can't seem to figure out why my C program won't read the last unsigned int.

    On line 23, the last variable (unsigned int spartyCount = 0 isn't read. Once I enter the letter M in the second switch, once I exit out (by hitting Y and the Z), the printf doesn't count up the number of times I hit M.

    The same thing happens for any int that's on the bottom of the list of integers. If wolvCount was on the bottom of the list, the letter W would not be counted into the last printf statement, either.

    I have attached the C program file below.
    Code:
    #include <stdio.h>
    
    /*
    You shall fix the following program and the program must also do the following:
        add up all of the times for Tigers, Red Wings, Pistons or school
        add a new section called S
            then ask for Grizzly, Wolverine or Sparty
        At the end of the program:
            print out how many for each catagory
            Fix the problem with the dafault option
    
    */
    
    int main( void )
    {
        char team;
        unsigned int tigerCount = 0;
        unsigned int wingCount = 0;
        unsigned int pistCount = 0;
        char team2;
        unsigned int grizzCount = 0;
        unsigned int wolvCount = 0;
        unsigned int spartyCount = 0;
    
    
        printf("Enter T for Tigers, R for Red Wings, or P for Pistons.\n");
        printf("The loop will end once Z is entered.\n");
    
        do
        {
            scanf("%s", &team);
            printf("You entered team %c.\n", team);
            switch(team)
            {
                case 'T':
                    printf("Tigers are da bomb.\n");
                    tigerCount++;
                    break;
                case 'R':
                    printf("Red Wings are da bomb.\n");
                    wingCount++;
                    break;
                case 'P':
                    printf("Piston are da bomb.\n");
                    pistCount++;
                    break;
    
                case 'S':
                    printf("Enter G for Grizzly, W for Wolverine, or M for Sparty.\n");
                    printf("This loop will end once you enter Y.\n");
                        do
                        {
                            scanf("%s", &team2);
                            printf("You entered team %c.\n", team2);
                            switch(team2)
                            {
                            case 'G':
                                printf("Grizzlies are da bomb.\n");
                                grizzCount++;
                                break;
                            case 'W':
                                printf("Wolverines are da bomb.\n");
                                wolvCount++;
                                break;
                            case 'M':
                                printf("Spartans are da bomb.\n");
                                spartyCount++;
                                break;
                            case '\n':
                            case '\t':
                            case ' ':
                                break;
                            default:
                                printf("Please enter another valid character.\n");
                                break;
                            }
                        } while (team2 != 'Y');
                        printf("Enter T for Tigers, R for Red Wings, or P for Pistons.\n");
                    break;
                case '\n':
                case '\t':
                case ' ':
                    break;
                default:
                    printf("Please enter a valid character.\n");
                    break;
            }
        } while (team != 'Z');
    
        printf("\n%u - Tigers %u - Red Wings %u - Pistons\n", tigerCount, wingCount, pistCount);
        printf("And the other schools...\n");
        printf("%u - Grizzlies %u - Wolverines %u - Spartans\n", grizzCount, wolvCount, spartyCount);
    
    }
    Attached Files Attached Files
    • File Type: c in.c (3.1 KB, 94 views)
    Last edited by Salem; 03-16-2017 at 12:28 AM. Reason: Removed useless fuzzy image and inlined the code

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc and cc can't recognize includes
    By telmo_d in forum C Programming
    Replies: 3
    Last Post: 03-09-2016, 11:44 AM
  2. gcc does not recognize my lib location
    By baxy in forum C Programming
    Replies: 2
    Last Post: 08-19-2013, 11:15 AM
  3. How to recognize an image on the screen
    By lala123 in forum C Programming
    Replies: 32
    Last Post: 02-17-2010, 08:08 PM
  4. Page File counter and Private Bytes Counter
    By George2 in forum Tech Board
    Replies: 0
    Last Post: 01-31-2008, 03:17 AM
  5. C++ code I can't recognize??
    By Guardian in forum Windows Programming
    Replies: 4
    Last Post: 04-29-2002, 04:31 PM

Tags for this Thread